﻿@using Janus.Cores.Tools
@using Janus.Mes.VO;
@model List<CalendarVO>
@{
    Layout = null;
    int curYear = -1;
    curYear = int.TryParse(ViewBag.CurrentYear, out curYear) ? curYear : -1;
    int monthRowCount = 0;
    int monthStartDay = 0;
    int dayCount = 0;
    List<int> lstMonthDays = CalendarHelper.GetEachMonthDays(curYear);
    CalendarVO curDateVO = new CalendarVO();
    DateTime curDate = DateTime.Now;
    int cellIndex = 0;
    string sDay = string.Empty;
    string sdayClass = string.Empty;
    int nDayType = 0;
    string isViewAction = ViewBag.IsViewAction;
}

<div class="photoerList calendar_container_content">
    @for (int i = 0; i < 12; i++)
    {
        <div class="photoer" style="height:190px;">
            <div class="pview third-effect">
                <table style="width:100%;height:100%;" class="calendarTable">
                    <tr>
                        <td colspan="7" style="text-align:center;">@curYear 年 @(i + 1) 月</td>
                    </tr>
                    <tr>
                        <td>日</td>
                        <td>一</td>
                        <td>二</td>
                        <td>三</td>
                        <td>四</td>
                        <td>五</td>
                        <td>六</td>
                    </tr>
                    @{
                        dayCount = 0;
                        //获得当月天数需要占用的行数
                        monthRowCount = CalendarHelper.GetMonthRowCount(curYear, i + 1);
                        //获取当月第一天是星期几
                        monthStartDay = CalendarHelper.GetDayOfWeek(new DateTime(curYear, i + 1, 1));
                        for (int j = 0; j < monthRowCount; j++)
                        {
                            <tr class="clickableRow">
                                @for (int k = 0; k < 7; k++)
                                {
                                    cellIndex = j * 7 + k; //单元格自然序列号
                                    dayCount = cellIndex - monthStartDay + 1; //计算日期
                                                                              //过滤无效日期（小于等于零的、大于月总天数的）
                                    dayCount = (dayCount <= 0 || dayCount > lstMonthDays[i]) ? dayCount = -1 : dayCount = cellIndex - monthStartDay + 1;
                                    sDay = dayCount > 0 ? dayCount.ToString() : "";
                                    sdayClass = "";
                                    if (sDay != "")
                                    {
                                        curDate = new DateTime(curYear, i + 1, dayCount);
                                        curDateVO = Model.Where(c => c.Year == curYear && c.CDate == curDate).FirstOrDefault();
                                        if (curDate > DateTime.Now && isViewAction != "1")
                                        {
                                            sdayClass = " clickable";
                                        }
                                        nDayType = curDateVO != null ? curDateVO.Ctype : -1;
                                        switch (nDayType)
                                        {
                                            case 1:
                                                <td class="@(sdayClass)" cldr_date="@string.Format(curDate.Date.ToShortDateString(), "yyyy-MM-dd")" cldr_type_org="@nDayType" cldr_type_new="@nDayType">@sDay</td>
                                                break;
                                            case 2:
                                                <td class="weekend @(sdayClass)" cldr_date="@string.Format(curDate.Date.ToShortDateString(), "yyyy-MM-dd")" cldr_type_org="@nDayType" cldr_type_new="@nDayType">@sDay</td>
                                                break;
                                            case 3:
                                                <td class="legalHoliday @(sdayClass)" cldr_date="@string.Format(curDate.Date.ToShortDateString(), "yyyy-MM-dd")" cldr_type_org="@nDayType" cldr_type_new="@nDayType">@sDay</td>
                                                break;
                                            case 4:
                                                <td class="daysOff @(sdayClass)" cldr_date="@string.Format(curDate.Date.ToShortDateString(), "yyyy-MM-dd")" cldr_type_org="@nDayType" cldr_type_new="@nDayType">@sDay</td>
                                                break;
                                        }
                                    }
                                    else {
                                        <td>&nbsp;</td>
                                    }
                                }
                            </tr>
                        }
                    }
                </table>
            </div>
        </div>
                        }
    <div style="height:10px;width:0px;clear:both;"></div>
</div>

<script type="text/javascript">
    $(function () {
        var curDialog = $.pdialog.getCurrent();
        $("div.calendar_container_content", curDialog).find("td.clickable").each(function () {
            $(this).click(function () {
                handleCalendarClick($(this));
            });
        });
    });

    function handleCalendarClick($obj) {
        var curDialog = $.pdialog.getCurrent();
        var checkedVal = $("div.calendar_container_header", curDialog).find("input.calendarRadio:checked").val();
        if (checkedVal != null && checkedVal != undefined && checkedVal != "") {
            switch (checkedVal) {
                case "1": $obj.removeClass("weekend").removeClass("legalHoliday").removeClass("daysOff").addClass("workDay"); $obj.attr("cldr_type_new", checkedVal); break;
                case "2": $obj.removeClass("workDay").removeClass("legalHoliday").removeClass("daysOff").addClass("weekend"); $obj.attr("cldr_type_new", checkedVal); break;
                case "3": $obj.removeClass("workDay").removeClass("weekend").removeClass("daysOff").addClass("legalHoliday"); $obj.attr("cldr_type_new", checkedVal); break;
                case "4": $obj.removeClass("workDay").removeClass("legalHoliday").removeClass("weekend").addClass("daysOff"); $obj.attr("cldr_type_new", checkedVal); break;
                default: break;
            }
        }
    }
</script>
